package com.bossYang.myBatisTest;

import com.bossYang.myBatisTest.bean.InterEmployee;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName MyBatisInitDemo
 * @Description TODO
 * @Author will
 * @Date 2020/11/8 10:03 PM
 */
public class MyBatisInitDemo {
    public static void main(String[] args) throws IOException {
        String myBatisCfgResource = "config/mybatis-config.xml";
        InputStream resource = Resources.getResourceAsStream(myBatisCfgResource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            InterEmployee param = new InterEmployee();
            param.setId("08b8755629e8482da80e329e6b8b7221");

            InterEmployee interEmployee = sqlSession.selectOne("com.bossYang.myBatisTest.dao.InterEmployeeDao.queryInterEmployeeById", param);
            if (interEmployee != null) {
                System.out.println("interEmployee = " + interEmployee);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sqlSession.close();
        }
    }
}
